/******************************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd.                       */
/*                                                                            */
/*  NAME      = postgresql_comm.h                                             */
/*  NOTE      =                                                               */
/*  DATE      = 2016/01/06 by zhengxd                                         */
/******************************************************************************/
#ifndef _POSTGRESQL_COMM_H_
#define _POSTGRESQL_COMM_H_

#define POSTGRESQL_TEXT           0
#define POSTGRESQL_BINARY         1

void postgresql_dbg(void);

int postgresql_atol(char *p_inbuff, unsigned long *p_ul_len);

void postgresql_quicksort(int i_start, int i_right);

int postgresql_err_code(char *p_err_code);

int postgresql_skip_len(Frbyte_Packet *p_st_data
                        , int i_len
                        , int *p_i_len);

int postgresql_get_short(Frbyte_Packet *p_st_data
                        , int *p_i_len
                        , int *p_i_value);

int postgresql_get_int(Frbyte_Packet *p_st_data
                      , int *p_i_len
                      , int *p_i_value);

int postgresql_get_int2(Frbyte_Packet *p_st_data
                       , int *p_i_value);

int postgresql_skip_string(Frbyte_Packet *p_st_data
                           , int *p_i_len);

int postgresql_get_string(Frbyte_Packet *p_st_data
                         , int *p_i_len
                         , char **pp_out_str);

int psotgresql_get_bind(Frbyte_Packet *p_st_data
                        , int *p_i_len
                        , int i_data_len
                        , char c_data_type
                        , Sql_field_bind *p_lst_bind);

void postgresql_free_cmd(Postgresql_req_cmd **pp_st_command);

void postgresql_cmd_node_free(Frlist_node *p_st_node);

void postgresql_init_fragment(L7_fragment_postgresql *p_st_fragment
                             , int i_need_req_resp);

void postgresql_destroy_fragment(L7_fragment_postgresql **pp_st_fragment);

void postgresql_destroy_session(L7session_postgresql **pp_st_sess);

void postgresql_destroy_request(L7_req_postgresql **pp_st_req);

void postgresql_destroy_response(L7_resp_postgresql **pp_st_resp);

Frreport_body_data* postgresql_new_report_body(Conntrack *p_st_conn
                                             , L7session_postgresql *p_st_sess);

#endif
